#include "space\configuration.h"
#include "space\types.h"
#include "space\includes\base_debug.h"

#include <string>
#include <libconfig.hh>
using namespace libconfig;


namespace space {

	namespace configuration {
		namespace graphics {
			int resolution_w = 1280;
			int resolution_h = 1024;
			bool fullscreen = false;
		};
		namespace debug {
			space::bit_flag current_log_level			= space::debug::log_level::trace | space::debug::log_level::code | space::debug::log_level::critical | space::debug::log_level::debug | space::debug::log_level::info;
			space::bit_flag current_log_verbosity		= space::debug::log_verbosity::extreme;

			std::string current_log_file				= "space.log";
			space::debug::logger *current_log_object	= NULL;
		};


		static Config _config;
		static result load_configuration_file(char *filename) {
			try {
				_config.readFile(filename);

				// graphics
				_config.lookupValue("graphics.resolution.w", graphics::resolution_w);
				_config.lookupValue("graphics.resolution.h", graphics::resolution_h);
				_config.lookupValue("graphics.fullscreen", graphics::fullscreen);

				// debug
				_config.lookupValue("debug.log_level", debug::current_log_level);
				_config.lookupValue("debug.log_verbosity", debug::current_log_verbosity);

				_config.lookupValue("debug.log_file", debug::current_log_file);

			} catch(...) {
				// TODO: silently fail on bad config
				return RESULT_ERROR;
			}
			return RESULT_OK;
		}
	};

};